package com.zeyi.chat.views;

import com.zeyi.chat.po.User;
import com.zeyi.chat.utils.AvatarUtil;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.Pane;
import javafx.scene.shape.Rectangle;

/**
 * @author zeyi
 */
public class MemberListItem {

    Pane pane;
    ImageView avatar;
    Label username;

    public MemberListItem(User user) {
        pane = new Pane();
        avatar = new ImageView(new Image(AvatarUtil.suffix + user.getAvatar()));
        username = new Label(user.getUsername());
        pane.setPrefWidth(175);
        pane.setPrefHeight(40);
        avatar.setFitWidth(25);
        avatar.setFitHeight(25);
        avatar.setLayoutX(14);
        avatar.setLayoutY(8);
        setCircleAvatar();
        username.setLayoutX(51);
        username.setLayoutY(10);
        username.setStyle("-fx-text-fill: inherit;");
        pane.getChildren().addAll(avatar, username);
    }

    public Pane create() {
        return pane;
    }

    private void setCircleAvatar() {
        Rectangle rectangle = new Rectangle(avatar.prefWidth(-1), avatar.prefHeight(-1));
        rectangle.setArcHeight(avatar.prefHeight(-1));
        rectangle.setArcWidth(avatar.prefWidth(-1));
        avatar.setClip(rectangle);
    }
}
